﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace TiDiSun
{
    public partial class Update_Sanpham_Bokichdien : Form
    {
        public Update_Sanpham_Bokichdien()
        {
            InitializeComponent();
        }

        public int id { get; set; }

        private void Update_Sanpham_Bokichdien_Load(object sender, EventArgs e)
        {
            try
            {
                id = int.Parse(this.Tag.ToString());
                Sanpham_BochuyendoidienDTO bochuyen = new Sanpham_BochuyendoidienDTO();
                bochuyen = BoChuyenDoiDienBUS.load_sanpham_bochuyendoi_id(id);

                txtSanpham_bcd_congsuat.Text = bochuyen.congsuat;
                txtSanpham_bcd_loai.Text = bochuyen.loai;
                txtSanpham_bcd_giatien.Text = bochuyen.giatien.ToString();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        // event text changed----------------------------------------------------------------
        private void txtSanpham_bcd_congsuat_TextChanged(object sender, EventArgs e)
        {
            txtSanpham_bcd_congsuat.ForeColor = System.Drawing.Color.Black;
        }

        private void txtSanpham_bcd_loai_TextChanged(object sender, EventArgs e)
        {
            txtSanpham_bcd_loai.ForeColor = System.Drawing.Color.Black;
        }

        private void txtSanpham_bcd_giatien_TextChanged(object sender, EventArgs e)
        {
            txtSanpham_bcd_giatien.ForeColor = System.Drawing.Color.Black;
        }


        // event leave---------------------------------------------------------------------------------
        private void txtSanpham_bcd_congsuat_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSanpham_bcd_congsuat.Text))
            {
                txtSanpham_bcd_congsuat.Text = "Hãy nhập";
                txtSanpham_bcd_congsuat.ForeColor = System.Drawing.Color.DarkGray;
            }
        }

        private void txtSanpham_bcd_loai_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSanpham_bcd_loai.Text))
            {
                txtSanpham_bcd_loai.Text = "Hãy nhập";
                txtSanpham_bcd_loai.ForeColor = System.Drawing.Color.DarkGray;
            }
        }

        private void txtSanpham_bcd_giatien_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSanpham_bcd_giatien.Text))
            {
                txtSanpham_bcd_giatien.Text = "Hãy nhập";
                txtSanpham_bcd_giatien.ForeColor = System.Drawing.Color.DarkGray;
            }
        }


        // event click-----------------------------------------------------------------
        private void txtSanpham_bcd_congsuat_Click(object sender, EventArgs e)
        {
            if (txtSanpham_bcd_congsuat.Text == "Hãy nhập")
                txtSanpham_bcd_congsuat.Text = "";
        }

        private void txtSanpham_bcd_loai_Click(object sender, EventArgs e)
        {
            if (txtSanpham_bcd_loai.Text == "Hãy nhập")
                txtSanpham_bcd_loai.Text = "";
        }

        private void txtSanpham_bcd_giatien_Click(object sender, EventArgs e)
        {
            if (txtSanpham_bcd_giatien.Text == "Hãy nhập")
                txtSanpham_bcd_giatien.Text = "";
        }

        private void btnThem_sanpham_bochuyendoi_Click(object sender, EventArgs e)
        {
            try
            {
                Sanpham_BochuyendoidienDTO bochuyen = new Sanpham_BochuyendoidienDTO();
                bochuyen.id = id;
                bochuyen.congsuat = txtSanpham_bcd_congsuat.Text;
                bochuyen.loai = txtSanpham_bcd_loai.Text;
                bochuyen.giatien = float.Parse(txtSanpham_bcd_giatien.Text);

                BoChuyenDoiDienBUS.Update_sanpham_bochuyendoi(bochuyen);
                this.Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        // gia tien hai la so--------------------------------------------------------------
        private void txtSanpham_bcd_giatien_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && e.KeyChar != '.')
                e.Handled = true;
        }











    }
}
